/*
*
*	SELLER
*
*/

BeliefUpdates:
	
	{toSell( Item, Price )}	HasAdoptedSell( Item, Price ) 	{ not toSell( Item, Price ), selling( Item, Price ) }
	
	{ selling( Item, MinPrice ) }	Sold( Item, Price )		{ sell( Item, MinPrice ), sold( Item, Price ), not selling( Item, MinPrice ), not confirmSellAcceptSend(Item) }

	{selling(Item,MinPrice)} ConfirmSellAcceptSend(Item) {confirmSellAcceptSend(Item)}
	
PG-rules:
	
	true <- toSell( Item, Price ) and waiting( WaitTime ) |
	{
		adopta( sell( Item, Price ) );
		HasAdoptedSell( Item, Price );
		wait( WaitTime );
		
		send( maintainer, inform, registerOffer( Item ) )
	}

	
PC-rules:
	
	/*
	 * Message received from a Buyer with an auction bid.
	 * Item: The item which is bid on.
	 * Bid: The bid that is offered.
	 */
	message( Buyer, request, _, _, auctionBid( Item, Bid ) ) <- selling( Item, Price ) |
	{
		if B( Bid < Price ) then
			{ send( Buyer, inform, replyOnBid( Item, Bid, reject ) ) }
		else
			{ send( Buyer, inform, replyOnBid( Item, Bid, accept ) ) } 	
	}	 
	
	/*In the case the item is not sold any more, but the buyer is not informed yet of the removed offer. */
	
	message( Buyer, request, _, _, auctionBid( Item, Bid ) ) <- true |
	{
		send(Buyer,inform,replyOnBid(Item,Bid,reject))
	}
	
	
	/*
	 * Message received from Buyer action for a confirm for Selling to him
	 * Item: The item to sell
	 * Bid: The price to sell for
	 */
	message (Buyer, request, _, _, confirmReply( Item, Bid ) ) <- selling( Item, Price ) and
		Bid >= Price and not confirmSellAcceptSend(Item)|
	{
		ConfirmSellAcceptSend(Item);
		// Item is still in stock and Price is high enough
		send( Buyer, inform, confirmSell( Item, Bid, accept ) );
		print( "Just sold" ); print( Item ); print( "to" ); print( Buyer ); print( "for" ); print( Bid );
		send(maintainer,inform,removeOffer(Item));
		Sold( Item, Price )
		
	}
	
	message (Buyer, request, _, _, confirmReply( Item, Bid ) ) <- true |
	{
		// Item isn't in stock or bid is to low
		send( Buyer, inform, confirmSell( Item, Bid, reject ) );
		print( "Just rejected" ); print( Item ); print( "to" ); print( Buyer ); print( "for" ); print( Bid )
	}
	